/**
 * Created by on 2016/7/10.
 */
 
var redis = require('redis');


class redisMasterModel{

	constructor(){

		this.client={};

	}

	createClient(obj){
		
		this.client=redis.createClient(obj);

	}

	getRedisComments(){
		return new Promise((resolve,reject)=>{
			this.client.zrange('hash',0,-1,(err,res)=>{
				if (err) reject(err)
				resolve(res)
			})
		})
	}

	getUsersInform(id){
		return new Promise((resolve,reject)=>{
			this.client.get('users:'+id,(err,res)=>{
				if (err) reject(err)
				resolve(JSON.parse(res))
			})
		})
	}

	getUsersJobId(userid,timelimit){
		return new Promise((resolve,reject)=>{
			this.client.zrevrangebyscore('usersjobsid:'+userid,timelimit,'-inf',(err,res)=>{
				if (err) reject(err)
				resolve(res)
			})
		})
	}

	getUsersJobInfor(id){
		return new Promise((resolve,reject)=>{
			this.client.hget('usersjobid',id,(err,res)=>{
				if (err) reject(err)
				resolve(JSON.parse(res))
			})
		})
	}

	

}

module.exports = new redisMasterModel();
